<%@ Page language="c#" Inherits="Dimok.Aspx.Manager.Common.Dealers" CodeFile="Dealers.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns:amfc>
<head>
<title>Dealers</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<?IMPORT namespace="amfc" implementation="/include/htc/datagrid.htc">
<script src="/include/common.js"></script>
<script src="/include/soap.js"></script>
<script src="/include/RDS.js"></script>
<script src="/include/XML.js"></script>
</head>
<body style="background-color:menu;" bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0" onload="window.focus();cropWindow()">
<table height="100%" width="100%">
	<tr height="80%">
		<td>
			<amfc:htcDatagrid id="dtgList" caption="Dealers" allowEdit="true" allowAdd="true" allowDelete="true"
							style="height:100%;overflow-x:visible"
							hiddenFields="id,namespace"
							onFilter="filterRecords(this)"
							onDelete="deleteRecord('Delete')"
							onEdit="editRecord('Update')"
							onAdd="addRecord(this,'Add')"
							onrowselected="showSubList()">
					<RS>
						<asp:Literal ID="ltrList" Runat="server"></asp:Literal>
					</RS>
			</amfc:htcDatagrid>
		</td>
	</TR>
	<TR>
		<td>
			<amfc:htcDatagrid id="dtgSubList" caption="Contacts" allowEdit="true" allowAdd="true" allowDelete="true"
							hiddenFields="ID,DealerID"
							allowFilter="false"
							onDelete="deleteRecord('SubList_Delete')" onAdd="addSubList()" onEdit="editRecord('SubList_Update')">
			</amfc:htcDatagrid>
		</td>
	</tr>
</table>
</body>
<HEAD>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</HEAD>
</html>
<script>
initWS("DEALERS","Dealers.asmx");
function deleteRecord(webMethod){
	var rs = event.rs;
	if( !checkWS() || !confirm("Delete "+rs("Name")+"?") )return event.returnValue = false;
	var ret = WS(CO(webMethod),_getID());
	if(showSOAPError(ret)) return event.returnValue = false;
}
function editRecord(webMethod){
	if(!checkWS()) event.returnValue = false;
	var ret = WS(CO(webMethod),_getID(),event.fieldName,event.fieldValue);
	if(showSOAPError(ret)) return event.returnValue = false;
}
function addRecord(grid,webMethod){
	if(!checkWS()) return event.returnValue = false;
	var rs = event.rs;
	var ret = WS(CO(webMethod),getDSFromRS(rs,"xmlList"));
	if( showSOAPError(ret) )return event.returnValue = false;
	var ID = ret.value;
	var filter = (event.rs.Filter?"("+event.rs.Filter+") OR ":"") + (rs(0).Name +" = "+ID);
	var strRS = getList(filter);
	if( strRS === false )return;
	grid.setRecordset(strRS,filter);
	if( grid.recordCount == 1 )
		showSubList(ID);
}
function filterRecords(select){
	if(!checkWS()) return event.returnValue = false;
	var filter = (event.rs.filter||"").replace(/[*]/g,"%");
	var strRS = getList(filter);
	if( strRS === false )return event.returnValue = false;
	event.returnValue = select.setRecordset(strRS);
	if( select.recordCount == 1 )showSubList(select.recordset.Fields(0).Value);
}
function getList(filter){
	if( !checkWS() )return false;
	var ret = WS(CO("List"),(filter||""));
	if( showSOAPError(ret) )return false;
	return ret.value;
}
// ***** Contacts *****
function showSubList(ID){
	if(!checkWS(true)) return setTimeout("showSubList("+(ID||_ID())+")",1000);
	WS(function(ret){cb(ret,_Name())},"SubList",ID||_getID());
	// Local
	function cb(ret,name){
		if( showSOAPError(ret) )return;
		dtgSubList.caption = "Sublist for "+name;
		dtgSubList.recordset = ret.value;
	}
}
function addSubList(){
	if(!checkWS()) return event.returnValue = false;
	var rs = event.rs;
	var ret = WS(CO("SubList_Add"),_ID(),getDSFromRS(rs));
	if( showSOAPError(ret) )return event.returnValue = false;
	showSubList(_ID());
}
// **** Properties *****
function _getID(){return event.rs("ID").value;}
function _ID(){ return dtgList.recordset.Fields("ID").Value } 
function _Name(){ return dtgList.recordset.Fields("Name").Value } 
</script>
